<template>
  <div id="aggregToSeach">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="频道" prop="channel">
          <el-select v-model="formInline.channel" disabled placeholder="">
            <el-option
              v-for="item in PlateList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择学院" prop="collegeId">
          <el-select v-model="formInline.collegeId" clearable placeholder="">
            <el-option
              v-for="item in collegeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="大鹏号" prop="dpAccount">
          <el-input
            clearable
            v-model="formInline.dpAccount"
            placeholder="大鹏号"
          ></el-input>
        </el-form-item>
        <el-form-item label="用户属性" prop="userAttribute">
          <el-select
            v-model="formInline.userAttribute"
            clearable
            placeholder=""
          >
            <el-option
              v-for="item in userPropList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签类型" prop="property">
          <el-select v-model="formInline.property" clearable placeholder="">
            <el-option
              v-for="item in tagTypeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签名称" prop="labelName">
          <el-input
            clearable
            v-model="formInline.labelName"
            placeholder="请输入标签"
          ></el-input>
        </el-form-item>
        <el-form-item label="排序" prop="orderWay">
          <el-select v-model="formInline.orderWay" placeholder="">
            <el-option
              v-for="item in orderByList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签操作人" prop="operatorUserId">
          <el-select
            clearable
            v-model="formInline.operatorUserId"
            placeholder=""
            filterable
          >
            <el-option
              v-for="(item, index) in personList"
              :key="'item' + index"
              :label="item.nickname"
              :value="item.dapengUserId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            class="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
// import { getCreateTime } from '@utils/pubFunction'
import { getDpNum } from '@/api/system/user'

export default {
  name: 'aggregContent',
  msg: '标签-聚合内容展示-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          channel: '', // 板块
          collegeId: '', // 选择学院
          dpAccount: '', // 用户名
          userAttribute: '', // 用户属性
          property: '', // 标签类型
          labelName: '', // 标签名称
          createTime: [],
          startTime: '',
          endTime: '',
          orderWay: '', // 排序
          operatorUserId: ''
        }
      }
    }
  },
  data() {
    return {
      PlateList: [
        // 人审结果
        { dictLabel: '全部', dictValue: '' }
      ],
      collegeList: [
        // 机审结果
        { dictLabel: '全部', dictValue: '' }
      ],
      // 用户属性
      userPropList: [{ dictLabel: '全部', dictValue: '' }],
      // 标签类型
      tagTypeList: [{ dictLabel: '全部', dictValue: '' }],
      // 排序
      orderByList: [],
      // 审核人
      personList: [{ nickname: '全部', dapengUserId: '' }],
      rules: {
        peopleAuditStatus: {},
        college: {},
        dpAccount: {},
        timeType: {},
        checkUserId: {},
        searchText: {}
      }
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    /* 获取数据状态 */
    async getStatusList() {
      // 频道
      let data1 = await sysNormalDisable('sys_label_channel', 'channelType')
      this.PlateList = this.PlateList.concat(data1)
      // 学院
      let data2 = await sysNormalDisable('sys_college', 'collegeType')
      this.collegeList = this.collegeList.concat(data2)
      // 用户属性
      let data3 = await sysNormalDisable('sys_labels_user_attribute')
      this.userPropList = this.userPropList.concat(data3)
      // 标签类型
      let data4 = await sysNormalDisable('sys_labels_attribute', 'tagsProperty')
      this.tagTypeList = this.tagTypeList.concat(data4)
      // 排序
      let data5 = await sysNormalDisable('sys_labels_order')
      this.orderByList = this.orderByList.concat(data5)
      // 标签操作人
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.personList = this.personList.concat(response)
      })
      //设置默认数据
      this.setDefaultValue()
      //触发获取列表
      this.$emit('toSearch')
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.orderWay = this.orderByList[1].dictValue
      // this.formInline.channel = this.$route.query.channel
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      //设置默认数据
      this.setDefaultValue()
    }
  }
}
</script>

<style lang="less">
#aggregContent {
  .el-input {
    &.el-input--suffix {
      width: 150px !important;
    }
  }
}
</style>
